package org.samoji.test;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.samoji.business.Address;
import org.samoji.business.Course;
import org.samoji.business.PhoneNumber;
import org.samoji.business.Professor;
import org.samoji.business.Student;

public class PreliminaryTestProf {

	Course corso1;
	Course corso2;
	Professor docente1;
	Professor docente2;
	Professor docente3;
	Student studente1;
	Student studente2;

	protected void setUp() throws Exception {
		super.setUp();
		Address indirizzo1 = new Address(1, "citta 1", "via 1");
		Address indirizzo2 = new Address(2, "citta 2", "via 2");
		Address indirizzo3 = new Address(3, "citta 3", "via 3");
		Address indirizzo4 = new Address(4, "citta 4", "via 4");
		PhoneNumber nt1 = new PhoneNumber("+41", "91", "111111");
		PhoneNumber nt2 = new PhoneNumber("+41", "91", "222222");
		PhoneNumber nt3 = new PhoneNumber("+41", "91", "333333");
		PhoneNumber nt4 = new PhoneNumber("+41", "91", "444444");
		PhoneNumber nt5 = new PhoneNumber("+41", "91", "555555");
		PhoneNumber nt6 = new PhoneNumber("+41", "91", "666666");
		PhoneNumber nt7 = new PhoneNumber("+41", "91", "777777");
		corso1 = new Course("nomeCourse1", "descrizioneCourse1");
		corso2 = new Course("nomeCourse2", "descrizioneCourse2");
		docente1 = new Professor("nomeProfessor1", "cognomeProfessor1");
		docente1.setAddress(indirizzo1);
		docente1.addPhoneNumber(nt1);
		docente1.addPhoneNumber(nt2);
		docente2 = new Professor("nomeProfessor2", "cognomeProfessor2");
		docente2.setAddress(indirizzo2);
		docente2.addPhoneNumber(nt3);
		docente3 = new Professor("nomeProfessor3", "cognomeProfessor3");
		docente3.setAddress(indirizzo3);
		docente3.addPhoneNumber(nt4);
		studente1 = new Student("nomeStudent1", "cognomeStudent1");
		studente1.setAddress(indirizzo3);
		studente1.addPhoneNumber(nt4);
		studente1.addPhoneNumber(nt5);
		studente2 = new Student("nomeStudent2", "cognomeStudent2");
		studente2.setAddress(indirizzo4);
		studente2.addPhoneNumber(nt6);
		studente2.addPhoneNumber(nt7);

		corso1.addProfessor(docente1);
		corso1.addProfessor(docente2);
		corso2.addProfessor(docente3);
		corso1.addStudent(studente1);
		corso1.addStudent(studente2);
		corso2.addStudent(studente2);
	}

	public void testProfessorIsPersona() {
		assertTrue(docente1 instanceof Persona);
	}

	public void testStudentIsPersona() {
		assertTrue(studente1 instanceof Persona);
	}

	public void testSomeProfessor() {
		Professor d = docente2;
		assertNotNull(d);
		assertEquals("nomeProfessor2", d.getNome());
		assertEquals("cognomeProfessor2", d.getCognome());
	}

	public void testSomeStudent() {
		Student s = studente1;
		assertNotNull(s);
		assertEquals("nomeStudent1", s.getNome());
		assertEquals("cognomeStudent1", s.getCognome());
	}

	public void testDocentiCorsi() {
		List<Professor> l = corso1.getDocenti();
		assertNotNull(l);
		assertEquals(2, l.size());
		assertEquals("nomeProfessor1", l.get(0).getNome());
		assertEquals("nomeProfessor2", l.get(1).getNome());
		List<Professor> m = corso2.getDocenti();
		assertNotNull(m);
		assertEquals(1, m.size());
		assertEquals("nomeProfessor3", m.get(0).getNome());
	}

	public void testCorsiProfessor() {
		Course c1 = docente1.getCourse();
		assertNotNull(c1);
		assertEquals("nomeCourse1", c1.getNome());
		Course c2 = docente2.getCourse();
		assertNotNull(c2);
		assertEquals("nomeCourse1", c2.getNome());
		Course c3 = docente3.getCourse();
		assertNotNull(c3);
		assertEquals("nomeCourse2", c3.getNome());
	}

	public void testStudentiCorsi() {
		List<Student> l = corso1.getStudenti();
		assertNotNull(l);
		assertEquals(2, l.size());
		assertEquals("nomeStudent1", l.get(0).getNome());
		assertEquals("nomeStudent2", l.get(1).getNome());
		List<Student> m = corso2.getStudenti();
		assertNotNull(m);
		assertEquals(1, m.size());
		assertEquals("nomeStudent2", m.get(0).getNome());
	}

	public void testCorsiStudent() {
		List<Course> l = studente2.getCorsi();
		assertNotNull(l);
		assertEquals(2, l.size());
		assertEquals("nomeCourse1", l.get(0).getNome());
		assertEquals("nomeCourse2", l.get(1).getNome());
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

}
